如何停止Spring Data JPA自动查询生成? 您所在的位置:网站首页 jpa 分页查询pageable 如何停止Spring Data JPA自动查询生成?

如何停止Spring Data JPA自动查询生成?

2023-04-20 05:37| 来源: 网络整理| 查看: 265

TL;DR

我也遇到过类似的问题,我花了很长时间才发现。在我的例子中,原来我的Impl类在不同的包上。

Repository Interface. : com.example.dao.repo.api.MyRepository Custom Interface : com.example.dao.repo.api.MyRepositoryCustom Custom Implementation Class: com.example.dao.repo.impl.MyRepositoryCustomImpl

这个问题没有解决,我们把impl类移到了interface包的下面。

Repository Interface. : com.example.dao.repo.MyRepository Custom Interface : com.example.dao.repo.MyRepositoryCustom Custom Implementation Class: com.example.dao.repo.impl.MyRepositoryCustomImpl分析

Spring Data创建存储库的方式似乎是它将尝试检测是否存在任何所谓的片段(自定义实现)。如果它可以检测到自定义接口而不是Impl类(无论是由于命名约定还是包位置),Spring将回退到生成方法的其他方法,这会导致误导性消息“No property xxx for xxx”。Spring Data文档实际上说了一些关于它的事情,但它很微妙,很容易错过:仓库基础结构试图通过扫描它发现仓库的包下面的类来自动检测自定义实现片段。这些类需要遵循附加后缀默认为Impl的命名约定。如果你打开了spring数据的调试级别日志,并且你的片段类被加载了,你应该可以看到如下的日志。否则这可能意味着Spring加载片段失败。(在SpringBoot 2.7中尝试过)

DEBUG [main] org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder [RepositoryBeanDefinitionBuilder.java:196] Registering repository fragment implementation: myRepositoryCustomImpl com.example.dao.repo.impl.MyRepositoryCustomImpl DEBUG [main] org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder [RepositoryBeanDefinitionBuilder.java:218] Registering repository fragment: myRepositoryCustomImplFragment附言

我知道这是一个很老的问题,但当我遇到这个问题,无法找到答案的任何地方,这是令人沮丧的。几乎每个答案都是关于命名约定。希望这将有助于其他谁有类似的问题。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有